<?php

declare(strict_types=1);

use function Hyperf\Support\env;
use function Hyperf\Support\value;
return [
    'enable' => [
        'discovery' => true,
        'register' => true,
    ],
    // Nacos 服务注册
    'providers' => [
        [
            'name' => 'TestRpcService',
            'protocol' => 'jsonrpc-http',
            'server' => 'jsonrpc-http',
            'service' => App\JsonRpc\TestService::class,
            'publish_to' => 'nacos',
        ],
    ],
    // Nacos 服务消费者
    'consumers'  => value(function () {
        $consumers = [];
        $services = [
            'TestService' => App\Interface\TestServiceInterface::class,
        ];
        foreach ($services as $name => $interface) {
            $consumers[] = [
                'protocol' => 'jsonrpc-http',
                'name' => $name,
                'load_balancer' => 'random',
                'service' => $interface,
                'registry' => [
                    'protocol' => 'nacos',
                    'address' => 'http://' .
                        env('CONFIG_NACOS_HOST', '127.0.0.1') .
                        ':' .
                        env('CONFIG_NACOS_PORT', 8848),
                    'username' => env('CONFIG_NACOS_USERNAME', 'nacos'),
                    'password' => env('CONFIG_NACOS_PASSWORD', 'nacos'),
                    'group_name' => env('CONFIG_NACOS_GROUP', 'DEFAULT_GROUP'),
                    'namespace_id' => env('CONFIG_NACOS_TENANT', 'public'),
                ]
            ];
        }
        return $consumers;
    }),
    'drivers' => [
        'nacos' => [
            // nacos server url like https://nacos.hyperf.io, Priority is higher than host:port
            // 'url' => '',
            // The nacos host info
            'host' => env('CONFIG_NACOS_HOST', '127.0.0.1'),
            'port' => env('CONFIG_NACOS_PORT', 8848),
            // The nacos account info
            'username' => env('CONFIG_NACOS_USERNAME', 'nacos'),
            'password' => env('CONFIG_NACOS_PASSWORD', 'nacos'),
            'guzzle' => [
                'config' => null,
            ],
            'group_name' => env('CONFIG_NACOS_GROUP', 'DEFAULT_GROUP'),
            'namespace_id' => env('CONFIG_NACOS_TENANT', 'public'),
            'heartbeat' => 5,
            'ephemeral' => true, //就是这个地方改了true！
        ],
    ],
];